<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="java.util.regex.Pattern"%>
<%@page import="java.sql.*"%>
<%@ page import="com.xpert.common.*"%>
<%
request.setCharacterEncoding("UTF-8");

String idx = "";
String title = "";
String writer = "";
String regdate = "";
String count = "";

try {
    String driverName = "oracle.jdbc.driver.OracleDriver";
    String url = "jdbc:oracle:thin:@localhost:1521:ora11";
    String dbUser = "binny";
    String dbPass = "binny";

    Class.forName(driverName);
    Connection con = DriverManager.getConnection(url, dbUser, dbPass);

    ResultSet rs = null;
    Statement stmt = con.createStatement();
    String sql = "SELECT * FROM board ORDER BY idx DESC";
    
    rs = stmt.executeQuery(sql);
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Model 1 board</title>
<link rel="stylesheet" type="text/css" href="/zmodel2/css/style.css" />
</head>
<body>
	<h1>Free Board</h1>
	<div id="board">
		<table>
			<tr>
				<th>번호</th>
				<th>제목</th>
				<th>작성자</th>
				<th>날짜</th>
				<th>조회수</th>
			</tr>
<%
    while(rs.next()) {
			request.setAttribute("idx", rs.getString("idx"));
			request.setAttribute("title", rs.getString("title"));
			request.setAttribute("writer", rs.getString("writer"));
			request.setAttribute("regdate", rs.getString("regdate"));
			request.setAttribute("count", rs.getString("count"));
%>
			<tr>
				<td>${idx}</td>
				<td><a href="view.jsp?idx=${idx}">${title}</a></td>
				<td>${writer}</td>
				<td>${regdate}</td>
				<td>${count}</td>
			</tr>
<%
    }
%>

		</table>
		<a href="write.jsp"><input type="button" value="글쓰기" /></a>
	</div>
</body>
</html>
<%
    con.close();
}
catch(Exception e) {
    out.println(e.getMessage());
    e.printStackTrace();
}
%>